# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Contributor: Olivier Mauras <olivier@mauras.ch>
# Contributor: Kevin Daudt <kdaudt@alpinelinux.org>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=salt-lts
pkgver=3006.9
pkgrel=2
pkgdesc="parallel remote execution system LTS Channel"
url="https://github.com/saltstack/salt"
arch="noarch"
license="Apache-2.0"
depends="
	procps
	py3-dateutil
	py3-distro
	py3-jinja2
	py3-jmespath
	py3-looseversion
	py3-markupsafe
	py3-msgpack
	py3-packaging
	py3-psutil
	py3-cryptography
	py3-pycryptodomex
	py3-pygit2
	py3-pyzmq
	py3-requests
	py3-tornado
	py3-yaml
	!salt
	!salt-master
	!salt-minion
	!salt-syndic
	!salt-api
	!salt-pyc
	!salt-doc
	!salt-master-openrc
	!salt-minion-openrc
	!salt-syndic-openrc
	!salt-api-openrc
	"
makedepends="python3-dev py3-setuptools py3-apache-libcloud py3-pbr"
subpackages="$pkgname-doc
	$pkgname-master $pkgname-master-openrc:master_openrc
	$pkgname-minion $pkgname-minion-openrc:minion_openrc
	$pkgname-syndic $pkgname-syndic-openrc:syndic_openrc
	$pkgname-api $pkgname-api-openrc:api_openrc
	$pkgname-pyc
	"
source="https://pypi.io/packages/source/s/salt/salt-$pkgver.tar.gz
	salt-api.confd
	salt-api.initd
	salt-master.confd
	salt-master.initd
	salt-minion.confd
	salt-minion.initd
	salt-syndic.confd
	salt-syndic.initd
	match_hostname.patch
	ignore_deprecations.patch
	fix-urllib.parse-module.patch
	"
options="!check" # depends on pytestsalt
builddir="$srcdir/salt-$pkgver"

build() {
	python3 setup.py build
}

check() {
	python3 setup.py test
}

package() {
	python3 setup.py install --root="$pkgdir"
	mkdir -p "$pkgdir"/var/log/$pkgname
}

master() {
	pkgdesc="Management component for salt, a parallel remote execution system"
	depends="$pkgname"

	_conf_copy master

	local i; for i in cp key master run; do
		_submv usr/bin/salt-$i
	done
	_submv usr/bin/salt
}

master_openrc() {
	pkgdesc="Management component for salt, a parallel remote execution system (OpenRC init scripts)"
	depends="openrc"
	install_if="openrc $pkgname-master=$pkgver-r$pkgrel"

	_init_copy master
}

minion() {
	pkgdesc="Client component for Salt, a parallel remote execution system"
	depends="$pkgname"

	_conf_copy minion
	_conf_copy proxy

	local i; for i in call minion proxy; do
		_submv usr/bin/salt-$i
	done
}

minion_openrc() {
	pkgdesc="Client component for Salt, a parallel remote execution system (OpenRC init scripts)"
	depends="openrc"
	install_if="openrc $pkgname-minion=$pkgver-r$pkgrel"

	_init_copy minion
}

syndic() {
	pkgdesc="Master-of-master component for Salt, a parallel remote execution system"
	depends="$pkgname-master"

	_submv usr/bin/salt-syndic
}

syndic_openrc() {
	pkgdesc="Master-of-master component for Salt, a parallel remote execution system (OpenRC init scripts)"
	depends="openrc"
	install_if="openrc $pkgname-syndic=$pkgver-r$pkgrel"

	_init_copy syndic
}

api() {
	pkgdesc="REST API for Salt, a parallel remote execution system"
	depends="$pkgname-master"

	_submv usr/bin/salt-api
}

api_openrc() {
	pkgdesc="REST API for Salt, a parallel remote execution system (OpenRC init scripts)"
	depends="openrc"
	install_if="openrc $pkgname-api=$pkgver-r$pkgrel"

	_init_copy api
}

cloud() {
	pkgdesc="Cloud provisioner for Salt, a parallel remote execution system"
	depends="$pkgname-master py3-apache-libcloud"

	_conf_copy cloud && _submv usr/bin/salt-cloud
}

ssh() {
	pkgdesc="Agentless SSH-based version of Salt, a parallel remote execution system"
	depends="$pkgname"

	_conf_copy roster && _submv usr/bin/salt-ssh
}

_submv() {
	local path="$1"
	mkdir -p "$subpkgdir"/${path%/*}
	mv "$pkgdir"/$path "$subpkgdir"/$path
}

_init_copy() {
	local type="$1"
	install -m 755 -D "$srcdir"/salt-$type.initd "$subpkgdir"/etc/init.d/salt-$type
	install -m 644 -D "$srcdir"/salt-$type.confd "$subpkgdir"/etc/conf.d/salt-$type
}

_conf_copy() {
	local type="$1"
	mkdir -p "$subpkgdir"/etc/salt/
	cp -r "$builddir"/conf/$type* "$subpkgdir"/etc/salt/
}

sha512sums="
96385f505363645d958c3a05f3d50b240f6c750b28e4a11b419c08ec152fc9a66930e555beeba282ef463986f4b570f6dda1ad944aefd14d4cce586a9f1741e1  salt-3006.9.tar.gz
975ba2f5e681fbd62045da61cc3dc065b148683a07b5df7eca9f131e47314eb6bfa8660ca1c06a3bd93683c7097d0ff9f8e514273dd24d82fb2de6a255e6b275  salt-api.confd
435d399bfecf431d0c713031e2ae57ce25b5c6edc98b62f33bd7a4ff1c587e3cdeb988445ae0c3e9ffc1911555c3694654d98815f9562b8a14bf0688ec1ebea6  salt-api.initd
cfbbeb8023a383e7c42d84e3346edfd068c9ec7650c4ddc3caa38534da325a67497e1f06ca02cc1f0941b7348a3af6d1dca7cd6f2bcb3612ca10e1ec98997e5a  salt-master.confd
40243f36a44150841ee74878029c011ab59f174640bf6c102b1f93b34d4ad2c12b291201882850ef8a4372c17dd96865cae6631d3b0f59db43c07bfbc1c5b9f6  salt-master.initd
0051e13351cef8db81dc075a194bb384723f07d5591b5b4d3f3adf4180afaf7beced470ab79ceca9d1ec0dae62dbd72084eb76af009fc78411a011050a94a2ed  salt-minion.confd
31521a7bf9455a805652ebb2c2a258148d654169caed500dbf1fe0c26baf26b330217117fe84a13706ded75a9eedadc0bbd671ede0957ed4d60d1e766fea6b39  salt-minion.initd
bafc6ea10cdafd0aef868feb35aecbe4ae6a7dff0ae42862bded85715ad763eb89e1ed27437866a7e5f2b9f7064e3c2a3fb59814487744ba4227238d95cf3818  salt-syndic.confd
d71133e834685304e0167554035ebbc861252f972bbe981cc71e45b70f15d94a28a02a369463c9a641372919689f96b62a0408b14f824ad986d536e52b1e5ec0  salt-syndic.initd
eadc8b7242dca02a04b34dab185663b9c54f4fc3a3fb3f1f753c3e21442a5ce89005a4458f735ec80ee1a7f1ee56743c9374012d354ac4cf7ac6afd547bb4ee4  match_hostname.patch
575829a4cd5e4779e050794243f7a44452f3a6b00b2eabe6eafbb1b0b2b98b30ca505a586fb20c86828938b0bc602e0ad6fcda6add575b7cda4e6d0b87f626d0  ignore_deprecations.patch
d606c572ee92846a6b37cee6be961e2d29b2398f899a93fccdf822226e956cd1c11d397f1e34929658441598d489682a08c28dfc1fc941047f45af3e8edeacbd  fix-urllib.parse-module.patch
"
